entry: Simplify selection rendering
authorMatthias Clasen <mclasen@redhat.com>
Wed, 11 Nov 2015 01:13:06 +0000 (20:13 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 11 Nov 2015 01:18:39 +0000 (20:18 -0500)
Calling gtk_render_background for each rectangle in the region
leads to suboptimal and sometimes weird results. Getting this
right requires more work in Pango first. Go back to just rendering
a single background, and clip it to the selection region. This
matches what GtkLabel does.

gtk/gtkentry.c

index c2b35d1fbb03f464e3d5f609f827e8c90a328ec0..251edd86f540e35c7a21d2aeadb2e92a71c6261e 100644 (file)
@@ -6493,14 +6493,14 @@ draw_text_with_color (GtkEntry *entry,
 {
   GtkEntryPrivate *priv = entry->priv;
   PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
-  GtkWidget *widget;
   gint x, y;
   gint start_pos, end_pos;
-
-  widget = GTK_WIDGET (entry);
+  GtkAllocation allocation;
 
   cairo_save (cr);
 
+  gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
+
   get_layout_position (entry, &x, &y);
 
   if (show_placeholder_text (entry))
@@ -6518,22 +6518,20 @@ draw_text_with_color (GtkEntry *entry,
       GdkRGBA text_color;
       GtkStyleContext *context;
 
-      context = gtk_widget_get_style_context (widget);
+      context = gtk_widget_get_style_context (GTK_WIDGET (entry));
       gtk_style_context_save_to_node (context, priv->selection_node);
 
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
-      for (i = 0; i < n_ranges; ++i)
-        gtk_render_background (context, cr,
-                               - priv->scroll_offset + ranges[2 * i], y,
-                              ranges[2 * i + 1], logical_rect.height);
-
       for (i = 0; i < n_ranges; ++i)
         cairo_rectangle (cr,
                          - priv->scroll_offset + ranges[2 * i], y,
                         ranges[2 * i + 1], logical_rect.height);
       cairo_clip (cr);
 
+      gtk_render_background (context, cr,
+                             0, 0, allocation.width, allocation.height);
+
       cairo_move_to (cr, x, y);
       gtk_style_context_get_color (context, gtk_style_context_get_state (context), &text_color);
       gdk_cairo_set_source_rgba (cr, &text_color);